package com.easy.controller;

import com.easy.bean.Production_schedule;
import com.easy.service.ProductionScheduleService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/api/production_schedule")
public class ProductionScheduleController {

    @Autowired
    ProductionScheduleService productionScheduleService;

    // 新增
    @PostMapping
    public Result add(@RequestBody Production_schedule schedule) {
        return Result.success(productionScheduleService.add(schedule));
    }

    // 编辑
    @PutMapping("/{id}")
    public Result edit(@PathVariable("id") Integer id, @RequestBody Production_schedule schedule) {
        schedule.setId(id);
        return Result.success(productionScheduleService.edit(schedule));
    }

    // 删除
    @DeleteMapping("/{id}")
    public Result del(@PathVariable("id") Integer id) {
        return Result.success("删除数据", productionScheduleService.del(id));
    }

    // 查询所有
    @GetMapping
    public Result all(
            @RequestParam(name = "production_order_id", required = false) Integer productionOrderId,
            @RequestParam(name = "assigned_employee_id", required = false) Integer assignedEmployeeId
    ) {
        return Result.success(productionScheduleService.all(productionOrderId, assignedEmployeeId));
    }

    // 查询单个
    @GetMapping("/{id}")
    public Result one(@PathVariable("id") Integer id) {
        return Result.success(productionScheduleService.one(id));
    }

    // 分页查询
    @GetMapping("page")
    public Result page(Page page, Production_schedule schedule){
        productionScheduleService.page(page, schedule);
        return Result.success(page);
    }
}